package org.example.http.demo;

import com.google.gson.Gson;
import org.example.http.*;

import java.io.IOException;
import java.util.Map;

public class LoginServlet extends HttpServletImpl {
    Gson gson = new Gson();
    @Override
    public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
        String username = request.getParameter("username");
        String password = request.getParameter("password");
        response.setContentType("application/json;charset=utf-8");
        if("yc".equals(username) && "123".equals(password)){
            request.getSession().setAttribute("username", username);
            gson.toJson(Map.of("code", 1, "msg", "登录成功"),
                    response.getWriter());
        }else{
            gson.toJson(Map.of("code", 0, "msg", "登录失败"),
                    response.getWriter());
        }
    }
}
